package com.sale.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.system.domain.SysAuxiliaryData;
import com.sale.system.domain.dto.SysAuxiliaryDataDto;
import com.sale.system.domain.dto.SysTheDropDto;
import com.sale.system.domain.dto.UnitMessageDto;
import com.sale.system.domain.vo.SysAuxiliaryDataVo;
import com.sale.system.service.ISysAuxiliaryDataService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: YSL
 * @Date: 2023/7/13 11:00
 * @Desc: 辅助资料
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/auxiliaryData")
public class SysAuxiliaryDataController extends BaseController {

    /**
     * 辅助资料
     */
    private final ISysAuxiliaryDataService sysAuxiliaryDataService;


    //************************************************* 辅助资料 *************************************************

    /**
     * 分页获取单计量多单位/其他列表
     *
     * @param SysAuxiliaryDataVo
     * @param pageQuery
     * @return
     */
    //@SaCheckPermission("system:auxiliaryData:list")
    @GetMapping("/list")
    public TableDataInfo<SysAuxiliaryData> list(SysAuxiliaryDataVo SysAuxiliaryDataVo, PageQuery pageQuery) {
        return sysAuxiliaryDataService.selectPageAuxiliaryList(SysAuxiliaryDataVo, pageQuery);
    }

    /**
     * 不分页获取单计量多单位/其他列表
     *
     * @param SysAuxiliaryDataVo
     * @param
     * @return
     */
    @GetMapping("/listNotPage")
    public R<?> listNotPage(SysAuxiliaryDataVo SysAuxiliaryDataVo) {
        return R.ok(sysAuxiliaryDataService.listNotPage(SysAuxiliaryDataVo));
    }

    /**
     * 根据id查询计量多单位/其他详情
     *
     * @param auxiliaryId 辅助资料ID
     */
    //@SaCheckPermission("system:auxiliaryData:query")
    @GetMapping(value = "/{auxiliaryId}")
    public R<SysAuxiliaryData> getInfo(@PathVariable Long auxiliaryId) {
        return R.ok(sysAuxiliaryDataService.getSingleMeasurementUnitById(auxiliaryId));
    }

    /**
     * 新增计量多单位/其他
     *
     * @param sysAuxiliaryDataVo
     * @return
     */
    //@SaCheckPermission("system:auxiliaryData:add")
    @Log(title = "辅助资料", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Void> add(@Validated @RequestBody SysAuxiliaryDataVo sysAuxiliaryDataVo) {
        return toAjax(sysAuxiliaryDataService.insertSingleMeasurementUnit(sysAuxiliaryDataVo));
    }

    /**
     * 修改计量多单位/其他
     *
     * @param sysAuxiliaryDataVo
     * @return
     */
    //@SaCheckPermission("system:auxiliaryData:edit")
    @Log(title = "辅助资料", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public R<Void> edit(@Validated @RequestBody SysAuxiliaryDataVo sysAuxiliaryDataVo) {
        return toAjax(sysAuxiliaryDataService.updateSingleMeasurementUnit(sysAuxiliaryDataVo));
    }

    /**
     * 删除计量多单位/其他
     *
     * @param auxiliaryId
     * @return
     */
    //@SaCheckPermission("system:auxiliaryData:remove")
    @Log(title = "辅助资料", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteSingle/{auxiliaryId}")
    public R<Void> remove(@PathVariable Long auxiliaryId) {
        return toAjax(sysAuxiliaryDataService.deleteSingleMeasurementUnit(auxiliaryId));
    }

    //************************************************* 辅助属性 *************************************************

    /**
     * 新增辅助属性
     *
     * @param sysAuxiliaryDataVo
     * @return
     */
    //@SaCheckPermission("system:auxiliaryData:insertAuxiliaryProperties")
    @Log(title = "辅助属性", businessType = BusinessType.INSERT)
    @PostMapping("/insertAuxiliaryProperties")
    public R<Void> insertAuxiliaryProperties(@Validated @RequestBody SysAuxiliaryDataVo sysAuxiliaryDataVo) {
        return toAjax(sysAuxiliaryDataService.insertAuxiliaryProperties(sysAuxiliaryDataVo));
    }

    /**
     * 修改辅助属性
     *
     * @param sysAuxiliaryDataVo
     * @return
     */
    //@SaCheckPermission("system:auxiliaryData:updateAuxiliaryProperties")
    @Log(title = "辅助属性", businessType = BusinessType.UPDATE)
    @PutMapping("/updateAuxiliaryProperties")
    public R<Void> updateAuxiliaryProperties(@Validated @RequestBody SysAuxiliaryDataVo sysAuxiliaryDataVo) {
        return toAjax(sysAuxiliaryDataService.updateAuxiliaryProperties(sysAuxiliaryDataVo));
    }

    /**
     * 分页获取辅助属性详情列表
     *
     * @param SysAuxiliaryDataVo
     * @param pageQuery
     * @return
     */
    //@SaCheckPermission("system:auxiliaryData:selectAuxiliaryPropertiesList")
    @GetMapping("/selectAuxiliaryPropertiesList")
    public TableDataInfo<SysAuxiliaryDataDto> selectAuxiliaryPropertiesList(SysAuxiliaryDataVo SysAuxiliaryDataVo, PageQuery pageQuery) {
        return sysAuxiliaryDataService.selectAuxiliaryPropertiesList(SysAuxiliaryDataVo, pageQuery);
    }

    /**
     * 查询辅助资料列表
     *
     * @param
     * @return
     */
    //@SaCheckPermission("system:auxiliaryData:selectAuxiliaryDtoList")
    @GetMapping("/selectAuxiliaryDtoList")
    public R<List<SysAuxiliaryDataDto>> selectAuxiliaryDtoList(String categoryType) {
        return R.ok(sysAuxiliaryDataService.selectAuxiliaryDtoList(categoryType));
    }

    /**
     * 根据id查询辅助属性详情
     *
     * @param auxiliaryId
     * @return
     */
    //@SaCheckPermission("system:auxiliaryData:getInfoAuxiliaryProperties")
    @GetMapping(value = "/getInfoAuxiliary/{auxiliaryId}")
    public R<SysAuxiliaryDataDto> getInfoAuxiliaryProperties(@PathVariable Long auxiliaryId) {
        return R.ok(sysAuxiliaryDataService.getInfoAuxiliaryProperties(auxiliaryId));
    }

    /**
     * 删除辅助属性
     *
     * @param auxiliaryId
     * @return
     */
    //@SaCheckPermission("system:auxiliaryData:deleteAuxiliaryProperties")
    @Log(title = "辅助资料", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteAuxiliaryProperties/{auxiliaryId}")
    public R<Void> deleteAuxiliaryProperties(@PathVariable("auxiliaryId") String auxiliaryId) {
        return toAjax(sysAuxiliaryDataService.deleteAuxiliaryProperties(auxiliaryId));
    }

    /**
     * 单计量单位下拉
     *
     * @return
     */
    @GetMapping("/selectUnitList")
    public R<List<SysTheDropDto>> selectUnitList() {
        return R.ok(sysAuxiliaryDataService.selectUnitList());
    }

    /**
     * 根据单计量单位id查询详情
     *
     * @return
     */
    @GetMapping("/getByAuxiliaryData/{auxiliaryId}")
    public SysAuxiliaryData getByAuxiliaryData(@PathVariable Long auxiliaryId) {
        return sysAuxiliaryDataService.getByAuxiliaryData(auxiliaryId);
    }

    /**
     * 其他支出类别
     *
     * @return
     */
    @GetMapping("/disburse")
    public R<List<SysTheDropDto>> selectDisburseList() {
        return R.ok(sysAuxiliaryDataService.selectDisburseList());
    }

    /**
     * 其他收入类别
     *
     * @return
     */
    @GetMapping("/income")
    public R<List<SysTheDropDto>> selectIncomeList() {
        return R.ok(sysAuxiliaryDataService.selectIncomeList());
    }

    /**
     * 根据物料id获取单位相关信息（入库打印使用）
     */
    @GetMapping("/getUnitMessage")
    public R<List<UnitMessageDto>> getUnitMessage(String materialId) {
        return R.ok(sysAuxiliaryDataService.getUnitMessage(materialId));
    }

}
